<?php
namespace Portal\Controller;
use Common\Controller\HomebaseController;
/**
 * 首页
 */
class MyController extends HomebaseController {
    public function __construct() {
        parent::__construct();
        $src = $this->getPhoto();
        //var_dump($src);
        $this -> assign("src",$src["photo"]);

    }

   //个人中心
    public function index(){
        $infor = M("infor");
        $count = session("tel");

        $arr = $infor->where("count = '$count'")->find();
        //$sql = $infor->getLastSql();
        //dump($sql);
        //var_dump($arr);
        $this->assign("myNav","1");
        $this->assign("data",$arr);
        $this->assign("count",$count);
        $this->display();
    }
    //我的消息
    public function msg(){

        $this->assign("myNav","6");
        $this->display();
    }
    //个人主页
    public function personal(){

        $this->assign("myNav","2");
        $this->display();
    }
    //修改密码
    public function resetPass(){

        $this->assign("myNav","3");
        $this->display();
    }
    //手机绑定
    public function setTel(){

        $this->assign("myNav","4");
        $this->display();
    }
    //添加信息
    public function subInfor(){

        //var_dump($_POST);
        //获取上传文件的临时信息
        //var_dump($_FILES['file']);
        $img = $_FILES['file']["name"];
        if($img){

            $upload = new \Think\Upload();  // 实例化上传类

            $upload->maxSize   =     3145728 ;  // 设置附件上传大小

            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');    // 设置附件上传类型

            $upload->savePath  =      './Uploads/';     // 设置附件上传目录    // 上传单个文件

            $info   =   $upload->uploadOne($_FILES['file']);

            if(!$info) {    // 上传错误提示错误信息

                $this->error($upload->getError());

            }else{      // 上传成功 获取上传文件信息

                //echo $info['savepath'].$info['savename'];
                $data["photo"] = $info['savepath'].$info['savename'];
            }
        }

        $data["count"] = $_POST["tel"];
        $data["nickname"] = $_POST["nickname"];
        $data["system"] = $_POST["sys"];
        $data["qq"] = $_POST["qq"];
        $data["wechat"] = $_POST["wechat"];
        //var_dump($data);

        $infor = M("infor");
        $num = $infor->where('count = '.$data["count"])->count();
        //var_dump($data);

        if($num){
            //已有账户，更新数据
            $n = $infor->where('count = '.$data["count"])->save($data);
            //var_dump($n);
            if($n){
                $this->success("数据修改成功",U("/"),2);
            }else{
                $this->error("没有数据被修改",U("My/index"),1);
            }
        }else{
            //没有数据，添加数据
            $n = $infor->add($data);
            //var_dump($n);
            //echo $n;
            if($n){
                $this->success("数据添加成功");
            }else{
                $this->error("数据添加失败");
            }
        }
    }
}


